package logic

import (
	"cart_srv/cart"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type HandlerCartDelLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewHandlerCartDelLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HandlerCartDelLogic {
	return &HandlerCartDelLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *HandlerCartDelLogic) HandlerCartDel(req *types.RequestCartDel) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line

	del, err := l.svcCtx.CartSrv.CartDel(l.ctx, &cart.CartDelRequest{UserId: int32(req.UserId)})
	if err != nil {
		return &types.Response{
			Msg:  "删除失败",
			Code: "500",
			Data: nil,
		}, nil
	}

	return &types.Response{
		Msg:  "删除成功",
		Code: "200",
		Data: del,
	}, nil
}
